<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
   <title>组织机构列表</title>
   <%@ include file="../../include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/3rd-lib/jquery-ztree/css/zTreeStyle.css">
</head>
<body>
<div class="admin-content">
    <div class="am-g">
        <div class="am-u-sm-3">
            <div class="am-panel am-panel-default">
                <div class="am-panel-hd">机构树</div>
                <div class="am-panel-bd">
                    <div class="am-scrollable-horizontal">
                        <ul id="tree" class="ztree"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="am-u-sm-9">
            <div class="am-panel am-panel-default">
                <div class="am-panel-hd">
                    机构列表
                    <shiro:hasPermission name="sys:organization:edit">
                    <button type="button" class="am-btn am-btn-primary am-btn-xs iu-right" onclick="openModel('新增','${ctx}/organization/create?id=${page.entity.id}')"><span class="am-icon-plus"></span> 新增</button>
                    </shiro:hasPermission>
                </div>
                <div class="am-panel-bd">
                    <div class="am-g">
                        <form id="searchForm" action="${ctx}/organization" method="post" style="display: none;">
                            <input name="id" value="${page.entity.id}" />
                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                            <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
                        </form>
                        <div class="am-u-sm-12">
                            <table id="contentTable" class="am-table am-table-striped am-table-hover table-main">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>归属机构</th>
                                    <th>机构名称</th>
                                    <th>是否可用</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${page.list}" var="org" varStatus="status">
                                    <tr>
                                        <td>${status.index+1}</td>
                                        <td>${org.organization.name}</td>
                                        <td>${org.name}</td>
                                        <td>${org.available?'<span class="am-badge am-badge-success am-radius">可用</span>':'<span class="am-badge am-badge-danger am-radius">禁用</span>'}</td>
                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <button class="am-btn am-btn-default am-btn-xs am-text-primary am-hide-sm-only" onclick="openModel('编辑','${ctx}/organization/update?id=${org.id}')"><span class="am-icon-pencil"></span> 编辑</button>
                                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="iuConfirm('确认要删除该条数据吗？', '${ctx}/organization/delete?id=${org.id}&pageNo=${page.pageNo}&pageSize=${page.pageSize}')"><span class="am-icon-trash-o"></span> 删除</button>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div class="am-u-sm-12">
                            <%@ include file="../../utils/pagination.jsp" %>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@ include file="../../include/bottom.jsp"%>
<script src="${ctxStatic}/3rd-lib/jquery-ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script>
    $(function () {
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback : {
                onClick : function(event, treeId, treeNode) {
                    location.href = "${ctx}/organization?id="+treeNode.id;
                }
            }
        };
        var zNodes =[
            <c:forEach items="${organizationList}" var="o" varStatus="status">
            { id:"${o.id}", pId:"${o.parentId}", name:"${o.name}"}<c:if test="${!status.last}">,</c:if>
            </c:forEach>
        ];
        $(document).ready(function(){
            var ztree = $.fn.zTree.init($("#tree"), setting, zNodes);
            ztree.expandAll(true);
        });
    });
</script>
<script>
  $(document).ready(function () {
      var msg = '${msg}';
      if(msg!=''){
          iuMsg(msg);
      }
  });
</script>
</body>
</html>